﻿using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Trippy.CollidableGameComponents;
using Trippy.CollidableGameComponents.Agents;
using Trippy.Levels;
using Trippy.Animation;

namespace Trippy.Abilities
{
    class Grow : Ability
    {
        public Grow(Level level) : base (level)
        {
            name = "Grow";
            icon = CurrentLevel.Game.Content.Load<Texture2D>("Sprites/Ability Icons/grow");
        }

        public override void OnAdd()
        {
            State = AbilityState.Available;
        }

        public override void OnActivate()
        {
            State = AbilityState.Active;
            CurrentLevel.Hero.Scale = new Vector2(2.0f, 2.0f);
            EffectAnimation e = new EffectAnimation(CurrentLevel, EffectAnimation.Effects.SmokeBomb, CurrentLevel.Hero.Position);
            e.AttachToComponent(CurrentLevel.Hero);
            base.OnActivate();
        }

        public override void OnCancel()
        {
            State = AbilityState.Available;
            CurrentLevel.Hero.Scale = new Vector2(1.0f, 1.0f);
            EffectAnimation e = new EffectAnimation(CurrentLevel, EffectAnimation.Effects.SmokeBomb, CurrentLevel.Hero.Position);
            e.AttachToComponent(CurrentLevel.Hero);
            base.OnCancel();
        }

        public override bool OnDie(Hero.MannerOfDeath d)
        {
            if (d != Hero.MannerOfDeath.Falling && State == AbilityState.Active)
            {
                CurrentLevel.Hero.RestoreAbility(); //will call OnTimer() anyway via OnRemove().
                CurrentLevel.Hero.CurrentAbility = new Invincibility(CurrentLevel, 2.0f);
                return false; //prevent one death, remove ability, grant invincibility for a few seconds, restore to old ability.
            }
            else
                return true; //won't save you from falling death.
        }

        public override void OnRemove()
        {
            if(State == AbilityState.Active)
                OnCancel();
            base.OnRemove();
        }
    }
}
